/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package evotingclient.data;

import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Agnieszka
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class Vote implements Serializable, Cloneable {

    @XmlTransient
    private Integer position;
    
    @XmlTransient
    private BigInteger voteCard;
    
    @XmlTransient
    private BigInteger hashVote;
    
    private BigInteger blindVote;
    
    private BigInteger blindSignVote;
    
    private BigInteger signUnblindVote;
    
    @XmlTransient
    private String name;

    public Vote() {
    }

    public Vote(Integer position) {
        this.position = position;
    }
    
    public Vote(Candidate can) {
        this.name = can.getName();
        this.position = can.getId();
    }

    private Vote(Vote vote) {
        this.voteCard = vote.getVoteCard();
    }

  

    public void calculateHashVote() throws UnsupportedEncodingException 
    {
        this.hashVote = new BigInteger((String.valueOf(position) + ";" + String.valueOf(voteCard)).getBytes("UTF-8"));
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
  
  
    
    public Integer getPosition() {
        return position;
    }

    public void setPosition(Integer position) {
        this.position = position;
    }

    public BigInteger getVoteCard() {
        return voteCard;
    }

    public void setVoteCard(BigInteger voteCard) {
        this.voteCard = voteCard;
    }

    public static String bigIntegerToString(BigInteger bi){
        return new String(bi.toByteArray());
    }
  
    public static BigInteger stringToBigInteger(String str) throws UnsupportedEncodingException {
        return new BigInteger(str.getBytes("UTF-8"));
    }

    @Override
    public Vote clone() {
        try {
            return (Vote) super.clone();
        } catch (CloneNotSupportedException ex) {
            Logger.getLogger(Vote.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    public BigInteger getBlindSignVote() {
        return blindSignVote;
    }

    public void setBlindSignVote(BigInteger blindSignVote) {
        this.blindSignVote = blindSignVote;
    }

    public BigInteger getBlindVote() {
        return blindVote;
    }

    public void setBlindVote(BigInteger blindVote) {
        this.blindVote = blindVote;
    }

    public BigInteger getHashVote() {
        return hashVote;
    }

    public void setHashVote(BigInteger hashVote) {
        this.hashVote = hashVote;
    }

    public BigInteger getSignUnblindVote() {
        return signUnblindVote;
    }

    public void setSignUnblindVote(BigInteger signUnblindVote) {
        this.signUnblindVote = signUnblindVote;
    }
    
}
